package pers.course.week9;

import java.util.*;

class Course {
    private int courseID;
    private String courseName;
    private int courseHour;
    private int courseCredit;
    public Course(int id, String name, int hour, int credit) {
        this.courseID = id;
        this.courseName = name;
        this.courseHour = hour;
        this.courseCredit = credit;
    }
    public int getCourseID() {
        return this.courseID;
    }
    public String getCourseName() {
        return this.courseName;
    }
    public int getCourseHour() {
        return this.courseHour;
    }
    public int getCourseCredit() {
        return this.courseCredit;
    }
    public void setCourseID(int courseID) {
        this.courseID = courseID;
    }
    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }
    public void setCourseHour(int courseHour) {
        this.courseHour = courseHour;
    }
    public void setCourseCredit(int courseCredit) {
        this.courseCredit = courseCredit;
    }
    @Override
    public String toString() {
        return courseID + ", "
                + "\"" + courseName + "\"" + ", "
                + courseHour + ","
                + courseCredit;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Course course = (Course) o;
        return courseID == course.courseID && courseHour == course.courseHour && courseCredit == course.courseCredit && Objects.equals(courseName, course.courseName);
    }
    @Override
    public int hashCode() {
        return Objects.hash(courseID, courseName, courseHour, courseCredit);
    }
}

public class AnalysisCourse {
    public static void main(String[] args) {
        List<Course> list = new ArrayList<>();
        Course s1 = new Course(1, "College Advanced Mathematics", 64,4);
        Course s2 = new Course(2, "College Physical Education", 36,1);
        Course s3 = new Course(3, "Java programming", 48,3);
        Course s4 = new Course(4, "English reading and writing AI", 32,2);
        Course s5 = new Course(4, "English reading and writing AI", 32,2);
        Course s6 = new Course(5, "form and policy", 96,2);
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);
        list.add(s6);
        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        for (Course s : list) {
            if (s.getCourseCredit() > 2) {
                sb1.append(s.toString()).append(",  ");
            }
        }
        String str1 = sb1.toString();
        System.out.println(str1.substring(0, str1.length() - 1));
        HashSet<Course> set = new HashSet<>(list.size());
        List<Course> result = new ArrayList<>(list.size());
        for (Course str : list) {
            if (set.add(str)) {
                result.add(str);
            }
        }
        list.clear();
        list.addAll(result);
        for (Course ssss : list) {
            sb2.append(ssss.toString()).append(", ");
        }
        String str2 = sb2.toString();
        System.out.println(str2.substring(0, str2.length() - 2) + " ");
    }
}
